package com.manager.core.module.manager.controller;

import com.alibaba.fastjson.JSON;
import com.manager.commons.annotation.Module;
import com.manager.commons.annotation.Operation;
import com.manager.commons.base.DataGrid;
import com.manager.core.module.log.aop.TMLog;
import com.manager.core.module.manager.entity.PlatformRole;
import com.manager.gen.module.platform.core.service.PlatformRoleService;
import com.manager.gen.web.controller.AdminController;
import com.manager.core.web.json.AjaxJson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

/**
 * 控制器
 *
 * @author H
 * @version 1.0
 */
@Controller
@Module(parent = "account-manager", title = "角色管理",code = "/platform/role")
public class PlatformRoleController extends AdminController<PlatformRole> {
    private final String baseUrl = "/platform/role";
    @Autowired
    private PlatformRoleService _service;

    @RequestMapping(baseUrl+"/add")
    @Operation(title = "新增")
    public ModelAndView add() {
        _map.put("dataThree", JSON.toJSONString(_service.queryPermissionnaxTree(getParams())));
        return getModelAndView(baseUrl + "/role-edit", getModel());
    }

    /**
     * 新增
     *
     * @return
     */
    @TMLog(type = "mvp", description = "访问编辑角色页面")
    @RequestMapping(baseUrl+"/edit")
    @Operation(title = "编辑")
    public ModelAndView platformUserEdit() {
        String tree=JSON.toJSONString(_service.queryPermissionnaxTree(getParams()));
        System.out.println(tree);
        _map.put("dataThree", tree);
        return getModelAndView(baseUrl + "/role-edit", _service.findMap(getParams()));
    }

    /**
     * 列表
     *
     * @return
     */
    @TMLog(type = "mvp", description = "访问角色列表页面。")
    @RequestMapping(baseUrl+"/index")
    public ModelAndView platformRoleList() {
        return getModelAndView(baseUrl + "/role-index");
    }

    /**
     * 分页
     *
     * @return
     */
    @TMLog(type = "page", description = "访问角色列表分页[post]。")
    @RequestMapping(value = baseUrl+"/list")
    @Operation(title = "列表")
    public @ResponseBody DataGrid platformListPage() {
        return _service.queryPage(getParams());
    }

    /**
     * 保存数据
     *
     * @return
     */
    @TMLog(type = "rmp", description = "保存角色数据[post]。")
    @RequestMapping(value = baseUrl+"/save", method = RequestMethod.POST)
    @Operation(title = "保存")
    public @ResponseBody AjaxJson platformRoleSave() {
        return _service.save(getParams());
    }

    /**
     * 改变数据状态
     *
     * @return
     */
    @TMLog(type = "rmp", description = "修改角色数据状态(禁用/启用)[post]。")
    @RequestMapping(value = baseUrl+"/status", method = RequestMethod.POST)
    @Operation(title = "状态修改")
    public @ResponseBody AjaxJson platformRoleStatus() {
        return _service.status(getParams());
    }

    /**
     * 删除数据
     *
     * @return
     */
    @TMLog(type = "rmp", description = "删除角色数据[post]。")
    @RequestMapping(value = baseUrl+"/delete", method = RequestMethod.POST)
    @Operation(title = "删除")
    public @ResponseBody AjaxJson platformRoleDelete() {
        return _service.delete(getParams());
    }

    /**
     * 销毁数据
     *
     * @return
     */
    @TMLog(type = "rmp", description = "销毁角色数据[post]。")
    @RequestMapping(value = baseUrl+"/destroy", method = RequestMethod.POST)
    public @ResponseBody AjaxJson platformRoleDestroy() {
        return _service.destroy(getParams());
    }


    @Override
    public PlatformRole getModel() {
        return new PlatformRole();
    }
}